{extend name="common/base" /}

{block name="tool_bar"}
<div class="layui-row">
    <div class="layui-col-md10">
        <form class="layui-form" action="">
            <div class="layui-col-md5" style="margin-left: 5px; line-height: 38px;">
                <div class="layui-form-item">
                    <input name="keyword" placeholder="请输入关键词" value="{$keyword}" class="layui-input"
                           type="text">
                </div>
            </div>
            <div class="layui-col-md4" style="margin-left: 5px; line-height: 38px;">
                <button class="layui-btn layui-btn-primary" lay-submit="" lay-filter="formDemo">
                    <i class="fa fa-search"></i>
                </button>
            </div>
        </form>
    </div>
    <div class="layui-col-md2 tr">
        <a href="{:url('add')}" id="addkw" class="layui-btn layui-btn-sm">增加关键词</a>
    </div>
</div>
{/block}


{block name="body"}
{include file="/common/reply_nav" /}
<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
    <ul class="layui-tab-title">
        <li class="<?=$type == 'all' ? 'layui-this' : '';?>">
            <a href="{:url('index',['type'=>'all'])}">全部</a>
        </li>
        {volist name="types" id="t"}
        <li class="<?=$type == $key ? 'layui-this' : '';?>">
            <a href="{:url('index',['type'=>$key])}">回复{$t}</a>
        </li>
        {/volist}
    </ul>

    <div class="layui-tab-content">
        {switch name="type"}
        {case value="text"}
        <table class="layui-table" lay-skin="line">
            <colgroup>
                <col width="120">
                <col>
                <col width="100">
                <col width="150">
            </colgroup>
            <thead>
            <tr>
                <th>关键词</th>
                <th>回复内容</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {volist name="data" id="vo"}
            <tr>
                <td>{$vo.keyword}</td>
                <td>{$vo.content}</td>
                <td>{if condition="$vo.status=='1'"}使用中{else/}已停用{/if}</td>
                <td>
                    <div class="">
                        <a class="bt-a" href="{:url('edit', ['id' => $vo['id']])}">修改</a>
                        {if condition="$vo.status=='1'"}
                        <a class="bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','0')">停用</a>
                        {else/}
                        <a class="bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','1')">开启</a>
                        {/if}
                        <a class="bt-a" href="javascript:;" onclick="delReply('{$vo.id}')">删除</a>
                    </div>
                </td>
            </tr>
            {/volist}
            </tbody>
        </table>
        {/case}
        {case value="image"}
        <table class="layui-table" lay-skin="line">
            <col width="">
            <col width="">
            <col width="100">
            <col width="150">
            <thead>
            <tr>
                <th>关键词</th>
                <th>封面图</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {volist name="data" id="vo"}
            <tr>
                <td>{$vo.keyword}</td>
                <td>
                    <img src="{$vo.url}" style="border: #e7e7eb 1px solid;width: 120px;">
                </td>

                <td>{if condition="$vo.status=='1'"}使用中{else/}已停用{/if}</td>
                <td>
                    <a class="bt-a" href="{:url('edit', ['id' => $vo['id']])}">修改</a>
                    {if condition="$vo.status=='1'"}
                    <a class="bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','0')">停用</a>
                    {else/}
                    <a class="bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','1')">开启</a>
                    {/if}
                    <a class="bt-a" href="javascript:;" onclick="delReply('{$vo.id}')">删除</a>

                </td>
            </tr>
            {/volist}
            </tbody>
        </table>
        {/case}

        {case value="news"}
        <table class="layui-table" lay-skin="line">
            <col width="120">
            <col width="200">
            <col width="150">
            <col width="">
            <col width="100">
            <col width="150">
            <thead>
            <tr>
                <th>关键词</th>
                <th>标题</th>
                <th>封面图</th>
                <th>图文描述</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {volist name="data" id="vo"}
            <tr>
                <td>{$vo.keyword}</td>
                <td>{$vo.title ?? '已删除'}</td>
                <td>
                    <div style="padding: 1px; border: #e6e6e6 solid 1px; width:120px; float: left; ">
                        <img class="form_logo" src="{$vo.cover_url}" style="max-width: none" width="120" height="60">
                    </div>
                </td>
                <td>{$vo.digest}</td>
                <td>{if condition="$vo.status=='1'"}使用中{else/}已停用{/if}</td>
                <td>
                    <div class="">
                        <a class="bt-a" href="{:url('edit', ['id' => $vo['id']])}">修改</a>
                        {if condition="$vo.status=='1'"}
                        <a class="bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','0')">停用</a>
                        {else/}
                        <a class="bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','1')">开启</a>
                        {/if}
                        <a class="bt-a" href="javascript:;" onclick="delReply('{$vo.id}')">删除</a>
                    </div>
                </td>
            </tr>
            {/volist}
            </tbody>
        </table>
        {/case}
        {case value="voice"}
        <table class="layui-table" lay-skin="line">
            <col width="">
            <col width="">
            <col width="">
            <col width="100">
            <col width="150">
            <thead>
            <tr>
                <th>关键词</th>
                <th>语音名称</th>
                <th>试听</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {volist name="data" id="vo"}
            <tr>
                <td>{$vo.keyword}</td>
                <td>{$vo.title}</td>
                <td>
                    <audio controls>
                        <source src="{$vo.url}" type="audio/mpeg">
                        <source src="{$vo.url}" type="audio/wma">
                        <source src="{$vo.url}" type="audio/wav">
                        <source src="{$vo.url}" type="audio/amr">
                        您的浏览器不支持 audio 元素。
                    </audio>
                </td>
                <td>{if condition="$vo.status=='1'"}使用中{else/}已停用{/if}</td>
                <td>
                    <a class="bt-a" href="{:url('edit', ['id' => $vo['id']])}">修改</a>
                    {if condition="$vo.status=='1'"}
                    <a class="bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','0')">停用</a>
                    {else/}
                    <a class="bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','1')">开启</a>
                    {/if}
                    <a class="bt-a" href="javascript:;" onclick="delReply('{$vo.id}')">删除</a>
                </td>
            </tr>
            {/volist}
            </tbody>
        </table>
        {/case}

        {case value="addon"}
        <table class="layui-table" lay-skin="line">
            <col width="120">
            <col width="200">
            <col width="">
            <col width="100">
            <col width="150">
            <thead>
            <tr>
                <th>关键词</th>
                <th>应用名称</th>
                <th>应用简介</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {volist name="data" id="vo"}
            <tr>
                <td>{$vo.keyword}</td>
                <td>
                    <div style=" float: left; ">
                        <img class="form_logo" src="{$vo.logo}" width="30" height="30">{$vo.name}
                    </div>
                </td>
                <td>{$vo.desc}</td>
                <td>{if condition="$vo.status=='1'"}使用中{else/}已停用{/if}</td>
                <td>
                    <a class="bt-a" href="{:url('edit', ['id' => $vo['id']])}">修改</a>
                    {if condition="$vo.status=='1'"}
                    <a class="bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','0')">停用</a>
                    {else/}
                    <a class="bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','1')">开启</a>
                    {/if}
                    <a class="bt-a" href="javascript:;" onclick="delReply('{$vo.id}')">删除</a>

                </td>
            </tr>
            {/volist}
            </tbody>
        </table>
        {/case}

        {case value="video"}
        <table class="layui-table" lay-skin="line">
            <col width="">
            <col width="">
            <col width="">
            <col width="80">
            <col width="150">
            <thead>
            <tr>
                <th>关键词</th>
                <th>视频标题</th>
                <th>视频地址</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {volist name="data" id="vo"}
            <tr>
                <td>{$vo.keyword}</td>
                <td>{$vo.title}</td>
                <td>
                    <a href="{$vo.url}" target="_blank" class="bt-a"><i class="fa fa-file-video-o"></i>点击试看</a>
                </td>
                <td>{if condition="$vo.status=='1'"}使用中{else/}已停用{/if}</td>
                <td>
                    <a class="bt-a" href="{:url('edit', ['id' => $vo['id']])}">修改</a>
                    {if condition="$vo.status=='1'"}
                    <a class="bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','0')">停用</a>
                    {else/}
                    <a class="bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','1')">开启</a>
                    {/if}
                    <a class="bt-a" href="javascript:;" onclick="delReply('{$vo.id}')">删除</a>

                </td>

            </tr>
            {/volist}
            </tbody>
        </table>
        {/case}

        {case value="music"}
        <table class="layui-table" lay-skin="line">
            <col width="80">
            <col width="100">
            <col width="">
            <col width="">
            <col width="100">
            <col width="150">
            <thead>
            <tr>
                <th>关键词</th>
                <th>音乐标题</th>
                <th>链接地址</th>
                <th>音乐描述</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {volist name="data" id="vo"}
            <tr>
                <td>{$vo.keyword}</td>
                <td>{$vo.title}</td>
                <td>
                    <audio controls>
                        <source src="{$vo.url}" type="audio/mpeg">
                        <source src="{$vo.url}" type="audio/wma">
                        <source src="{$vo.url}" type="audio/wav">
                        <source src="{$vo.url}" type="audio/amr">
                        您的浏览器不支持 audio 元素。
                    </audio>
                </td>
                <td>{$vo.desc}</td>
                <td>{if condition="$vo.status=='1'"}使用中{else/}已停用{/if}</td>
                <td>
                    <a class="bt-a" href="{:url('edit', ['id' => $vo['id']])}">修改</a>
                    {if condition="$vo.status=='1'"}
                    <a class="bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','0')">停用</a>
                    {else/}
                    <a class="bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','1')">开启</a>
                    {/if}
                    <a class="bt-a" href="javascript:;" onclick="delReply('{$vo.id}')">删除</a>

                </td>
            </tr>
            {/volist}
            </tbody>
        </table>
        {/case}

        {case value="all"}
        <table class="layui-table" lay-skin="line">
            <colgroup>
                <col width="120">
                <col>
                <col width="100">
                <col width="150">
            </colgroup>
            <thead>
            <tr>
                <th>关键词</th>
                <th>回复类型</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {volist name="data" id="vo"}
            <tr>
                <td>{$vo.keyword}</td>
                <td>{$types[$vo.media_type]}</td>
                <td>{if condition="$vo.status=='1'"}使用中{else/}已停用{/if}</td>
                <td>
                    <div class="">
                        <a class="bt-a" href="{:url('edit', ['id' => $vo['id']])}">修改</a>
                        {if condition="$vo.status=='1'"}
                        <a class="bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','0')">停用</a>
                        {else/}
                        <a class="bt-a" href="javascript:;" onclick="updateReply('{$vo.id}','1')">开启</a>
                        {/if}
                        <a class="bt-a" href="javascript:;" onclick="delReply('{$vo.id}')">删除</a>
                    </div>
                </td>
            </tr>
            {/volist}
            </tbody>
        </table>
        {/case}
        {/switch}
        <div id="page">
            {$page|raw}
        </div>
    </div>
</div>
{/block}

{block name="js"}
<script>
    var form;
    layui.use(['layer', 'form'], function () {
        form = layui.form;
        /*form.on('select(types)', function (data) {
            $.post("", {search_type: data.value}, function (res) {
            })
        });*/
    });

    function delReply(id) {
        layui.use('layer', function () {
            var layer = layui.layer;
            layer.confirm('你确定需要删除吗？', {
                btn: ['是', '不'] //按钮
            }, function () {
                $.post("{:url('mp/Mp/delRule')}", {'id': id}, function (res) {
                    if (res.status == 1) {
                        layer.alert(res.msg, function (index) {
                            window.location.reload();
                            layer.close(index);
                        })

                    } else {
                        layer.alert(res.msg)
                    }
                })
            }, function () {

            });
        });

    }

    /**
     * 启用／禁用
     * @param id
     * @param status
     */
    function updateReply(id, status) {
        var loading_index = layer.load(1);
        $.post("{:url('setStatusPost')}", {'id': id, 'status': status}, function (res) {
            layer.close(loading_index);
            if (res.code === 1) {
                layer.msg(res.msg, {time: 1500}, function (index) {
                    window.location.reload();
                })
            } else {
                layer.alert(res.msg);
            }
        })
    }
</script>
{/block}